package com.utilities.pipelineScripts;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class FileFormatter {

	String seqLength , initial_gc , initial_contigLength = null;
	String initial_reads, initialContigs , excluded_gc = null;
	String excluded_contigLength, excluded_reads, included_gc = null;
	String included_contigLength , included_reads , included_gapSize = null;
	String includedContigs, included_MappedLength, gapLength = null;
	String mergedContigs , merged_MappedLength , genesPossible = null;
	String gapsNoGenes , genesFound , genesMissing =  null;
	String genesInGapsButFound, excludedContigs = null;

	public enum FileTypes
	{
		XLS(0),
		TXT(1);
		
		int code;
		
		private FileTypes(int code)
		{
			this.code = code;
		}
		
		public int getCode() { return this.code; }
	}
	
	public void generateFiles(FileTypes[] types, String[] outFiles, String analyserFile)
	{
		int index = 0;
		initialise(analyserFile);
		if (! (types.length == outFiles.length))
		for(FileTypes type : types)
		{
			int code = type.getCode();
			switch(code)
			{
			case 0:
				generateXLSFile(outFiles[index]);
				break;
			case 1:
				generatePrettyFile(outFiles[index]);
				break;
			default: 
			}
			index++;
		}
	}
	
	private void initialise(String analyserFile)
	{
		Document doc = null;
		try
		{
			doc	= DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(analyserFile);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return;
		}

		Element element = (Element)doc.getElementsByTagName("refSize").item(0);
		seqLength = element.getTextContent();

		element = (Element)doc.getElementsByTagName("intialContigsData");
		initial_gc = element.getElementsByTagName("cgs").item(0).getTextContent();
		initial_contigLength = element.getElementsByTagName("contigLength").item(0).getTextContent();
		initial_reads = element.getElementsByTagName("reads").item(0).getTextContent();
		initialContigs = element.getElementsByTagName("contigs").item(0).getTextContent();
		element = (Element)doc.getElementsByTagName("excludedContigsData");

		excluded_gc = element.getElementsByTagName("cgs").item(0).getTextContent();
		excluded_contigLength = element.getElementsByTagName("contigLength").item(0).getTextContent();
		excluded_reads = element.getElementsByTagName("reads").item(0).getTextContent();
		excludedContigs = element.getElementsByTagName("contigs").item(0).getTextContent();

		element = (Element)doc.getElementsByTagName("includedContigsData");
		included_gc = element.getElementsByTagName("cgs").item(0).getTextContent();
		included_contigLength = element.getElementsByTagName("contigLength").item(0).getTextContent();
		included_reads = element.getElementsByTagName("reads").item(0).getTextContent();
		included_gapSize = element.getElementsByTagName("gaps").item(0).getTextContent();
		includedContigs = element.getElementsByTagName("contigs").item(0).getTextContent();
		included_MappedLength = element.getElementsByTagName("mappedLength").item(0).getTextContent();
		gapLength = element.getElementsByTagName("gapLength").item(0).getTextContent();

		element = (Element)doc.getElementsByTagName("mergedContigsData");
		mergedContigs = element.getElementsByTagName("contigs").item(0).getTextContent();
		merged_MappedLength = element.getElementsByTagName("mappedLength").item(0).getTextContent();

		element = (Element)doc.getElementsByTagName("genesData");
		genesPossible = element.getElementsByTagName("genesPossible").item(0).getTextContent();
		gapsNoGenes =  element.getElementsByTagName("gapsNoGenes").item(0).getTextContent();
		genesFound =  element.getElementsByTagName("genesFound").item(0).getTextContent();
		genesMissing =  element.getElementsByTagName("genesMissing").item(0).getTextContent();
		genesInGapsButFound = 	 element.getElementsByTagName("genesInGapsButFound").item(0).getTextContent();
	}
	private void generatePrettyFile(String outFileName)
	{
		
	}
	
	private void generateXLSFile(String outFileName)
	{
		
	}

}
